// ********************************************************************************************************
// Figure C3: Employment over parcel size and building footprint over parcel size by NAICS 3-digit industry
// ********************************************************************************************************

// Writes the results as reg_montreal to $resultpath/figures/
// Write also the table reg_parcel_sect to $resultpath/tables/

set scheme s2color

use "$outpath/database_for_reg.dta", clear

eststo clear

gen industry="Agrifood" if naics3d==311|naics3d==312
replace industry="Textile" if naics3d==313
replace industry="Textilep" if naics3d==314|naics3d==315| naics3d==316
replace industry="Wood" if naics3d==321|naics3d==322
replace industry="Printing" if naics3d==323
replace industry="Petrol" if naics3d==324
replace industry="Chemical" if naics3d==325
replace industry="Plastics" if naics3d==326
replace industry="Nonmetallic" if naics3d==327
replace industry="Primary" if naics3d==331
replace industry="Fabricated" if naics3d==332
replace industry="Machinary" if naics3d==333
replace industry="Computer" if naics3d==334
replace industry="Electrical" if naics3d==335
replace industry="Transportation" if naics3d==336
replace industry="Furniture" if naics3d==337
replace industry="Miscellaneous" if naics3d==339

global instruct "tdec(3) rdec(3) auto(3) bdec (3) symbol($^a$,$^b$,$^c$) se e(r2_p) tex label nocons"

xi: reghdfe Lnland_pwc Lnpopcma Lnareacma dist_min_NEW i.cat0 spacematep spacematep2 spacematep3 spacematep4 Lnemp i.hoffice i.exports NBdiffbusiness NBdiffnaics4 NBdiffproduct Lndist_maj_air Lndist_maj_sea Lndist_stat_freight Lndist_junction if samplep==1&industry=="Agrifood", absorb(naics4d eruid) cluster(cmauid)
estimates store coefAgrifood
outreg2 using "$resultpath/tables/reg_parcel_sect.xls", replace $instruct ctitle(Agrifood)

*We ignore Textile and Petrol and coal (too few observations), as well as miscellaneous (too heteroegeneous)
foreach n in "Textilep" "Wood" "Printing" "Chemical" "Plastics" "Nonmetallic" "Primary" "Fabricated" "Machinary" "Computer" "Electrical" "Transportation" "Furniture" "Miscellaneous"{
xi: reghdfe Lnland_pwc Lnpopcma Lnareacma dist_min_NEW i.cat0 spacematep spacematep2 spacematep3 spacematep4 Lnemp i.hoffice i.exports NBdiffbusiness NBdiffnaics4 NBdiffproduct Lndist_maj_air Lndist_maj_sea Lndist_stat_freight Lndist_junction if samplep==1&industry=="`n'", absorb(naics4d eruid) cluster(cmauid)
estimates store coef`n'
outreg2 using "$resultpath/tables/reg_parcel_sect.xls", append $instruct ctitle(`n')
	
}

coefplot (coefAgrifood, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Agrifood")) (coefTextilep, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Textile, clothing, leather")) (coefWood, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Wood and paper")) (coefPrinting, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Printing")) (coefChemical, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Chemical")) (coefPlastics, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Plastics")) (coefNonmetallic, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Non-metallic mineral")) (coefPrimary, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Primary metal")) (coefFabricated, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Fabricated metal product")) (coefMachinary, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Machinary")) (coefComputer, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Computer")) (coefElectrical, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Electrical products")) (coefTransportation, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Transportation")) (coefFurniture, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnemp) rename(Lnemp="Furniture")), legend(off) xtitle("Coef. Ln Emp.") grid(none) graphregion(color(white)) bgcolor(white) xline(0, lcolor(block) lpattern(dash))

graph export "$resultpath/figures/coef_emp_sect_parcel.pdf", replace
graph export "$resultpath/figures/coef_emp_sect_parcel.eps", replace

coefplot (coefAgrifood, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Agrifood")) (coefTextilep, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Textile, clothing, leather")) (coefWood, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Wood and paper")) (coefPrinting, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Printing")) (coefChemical, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Chemical")) (coefPlastics, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Plastics")) (coefNonmetallic, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Non-metallic mineral")) (coefPrimary, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Primary metal")) (coefFabricated, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Fabricated metal product")) (coefMachinary, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Machinary")) (coefComputer, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Computer")) (coefElectrical, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Electrical products")) (coefTransportation, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Transportation")) (coefFurniture, mcolor(black) ciopts(color(black) recast(rcap)) keep(Lnpopcma) rename(Lnpopcma="Furniture")) , legend(off) xtitle("Coef. Ln CMA Pop.") grid(none) graphregion(color(white)) bgcolor(white) xline(0, lcolor(block) lpattern(dash))

graph export "$resultpath/figures/coef_cma_size_sect_parcel.pdf", replace
graph export "$resultpath/figures/coef_cma_size_sect_parcel.eps", replace

coefplot (coefAgrifood, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Agrifood")) (coefTextilep, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Textile, clothing, leather")) (coefWood, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Wood and paper")) (coefPrinting, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Printing")) (coefChemical, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Chemical")) (coefPlastics, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Plastics")) (coefNonmetallic, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Non-metallic mineral")) (coefPrimary, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Primary metal")) (coefFabricated, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Fabricated metal product")) (coefMachinary, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Machinary")) (coefComputer, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Computer")) (coefElectrical, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Electrical products")) (coefTransportation, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Transportation")) (coefFurniture, mcolor(black) ciopts(color(black) recast(rcap)) keep(dist_min_NEW) rename(dist_min_NEW="Furniture")) , legend(off) xtitle("Coef. Ln Dist. centre") grid(none) graphregion(color(white)) bgcolor(white) xline(0, lcolor(block) lpattern(dash))

graph export "$resultpath/figures/coef_dist_sect_parcel.pdf", replace
graph export "$resultpath/figures/coef_dist_sect_parcel.eps", replace
